const fly = {
  state: {
    bgSpeed: 4, //背景图速度
    rockerSpeed: 6, //灵敏度
    troubdSpeed: 1,
    trajectoryData: {
      planeOffsetX: 0, //飞机x轴偏移量
      planeOffsetY: 0, //飞机y轴偏移量
      ballOffsetX: 0, //小球x轴偏移量
      ballOffsetY: 0, //小球y轴偏移量
    },
    planeSocer: {
      score: 0, //爱心奖励数
      hearts: 0, //爱心生成数
      crash: 0, //碰撞飞机数
      strike: 0, //打击飞机数
      enemys: 0, //敌机生成数
    },
    difficulty: 1, //游戏难度
    //游戏图片模型参数
    modelParmas: {
      yaoganX: "0", //速度摇杆X轴位置
      directionX: "0", //方向摇杆x轴
      directionY: "0", //方向摇杆y轴
      pedalX: "0", //脚踏板x轴
    },
  },

  mutations: {
    //设置背景图速度
    setBgSpeed(state, speed) {
      state.bgSpeed = speed;
      state.rockerSpeed = speed;
    },
    //设置灵敏度
    setRockerSpeed(state, speed) {
      state.rockerSpeed = speed;
    },
    setTroubdSpeed(state, speed) {
      state.troubdSpeed = speed;
    },
    //更新飞机位置数据
    updateFlyDataKey(state, payload) {
      for (let key in payload) {
        state.trajectoryData[key] = payload[key];
      }
    },
    //更新游戏数据
    updatePlanSocerKey(state, planeSocer) {
      for (let key in planeSocer) {
        state.planeSocer[key] = planeSocer[key];
      }
      let planeGameData = {
        code: "planeGameData",
        time: new Date().getTime(),
        gameScore: state.planeSocer,
      };
      if (this.getters.getConnectionStatus) {
        this.getters.getWebSocket.send(JSON.stringify(planeGameData));
      }
    },
    //更新飞机图片模型参数
    updateModelParmas(state, params) {
      for (let key in params) {
        state.modelParmas[key] = params[key];
      }
    },
    //设置游戏难度
    setDifficulty(state, difficulty) {
      state.difficulty = difficulty;
    },
  },

  actions: {},
};
export default fly;
